#include <stdio.h>
#include <stdlib.h>

typedef struct node {
	int value;

	struct node* left;
	struct node* right;
}tree;

void in_order_trav_print (tree *root)
{
	if (!root)
		return;

	in_order_trav_print (root->left);
	printf ("%d\t", root->value);
	in_order_trav_print (root->right);

	return;
}

tree * array_to_binary_search_tree (int a[], int start, int end)
{
	if (end >= start) {
		int mid;
		mid = (start + end) /2;

		tree *t;
		t = malloc (sizeof(tree));
		t->value = a[mid];
		t->left = array_to_binary_search_tree (a, start, mid-1);
		t->right = array_to_binary_search_tree (a, mid+1, end);

		return t;
	} else
		return NULL;
}

int main ()
{
	int a[] = {1, 2, 3, 4, 5, 6, 7};

	tree *t;
	t = array_to_binary_search_tree (a, 0, 6);
	
	in_order_trav_print (t);

	return 0;
}
